<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BSReourceGroup
 *
 * @author jianfeng
 */
class BSResourceGroup extends BSGroup {
    //put your code here
    const SPORT_TYPE = 2;
    const AREA = 3;
    const STADIUM = 4;

    const USER_RESOURCE = 'user_resource';
    
    public $name = 'no-name';
    public $description = 'no-description';
    public $rating = 0;
    public $picture = '';
    public $parentId = 0;
    
    public function getPropertyToColumnMapList($data = NULL) {
        $mapList = parent::getPropertyToColumnMapList($data);
        $mapList['parentId'] = 'parent_id';
        $mapList['rating'] = 'rating';
        $mapList['picture'] = 'picture';
        return $mapList;
    }
    
    public function initTreeEntityBeforeLoad(){
        self::initBeforeLoad();
    }
    
    public static function initBeforeLoad(){
        
        $root = BSResourceGroup::getRoot();
        
        $sportTypeRoot = new BSResourceGroup();
        $sportTypeRoot->name = 'Sport Type';
        $root->addChild($sportTypeRoot);
        
        $areaRoot = new BSResourceGroup();
        $areaRoot->name = 'Area';
        $root->addChild($areaRoot);
        
        $sportStadiumRoot = new BSResourceGroup();
        $sportStadiumRoot->name = 'Sport Stadium';
        $root->addChild($sportStadiumRoot);

        $sportType = new BSResourceGroup();
        $sportType->name = '羽毛球';
        $sportTypeRoot->addChild($sportType);

        $sportType = new BSResourceGroup();
        $sportType->name = '五人足球';
        $sportTypeRoot->addChild($sportType);

        $sportType = new BSResourceGroup();
        $sportType->name = '十一人足球';
        $sportTypeRoot->addChild($sportType);

        $sportType = new BSResourceGroup();
        $sportType->name = '七人足球';
        $sportTypeRoot->addChild($sportType);

        $sportType = new BSResourceGroup();
        $sportType->name = '篮球';
        $sportTypeRoot->addChild($sportType);

        $sportType = new BSResourceGroup();
        $sportType->name = '网球';
        $sportTypeRoot->addChild($sportType);

        $sportType = new BSResourceGroup();
        $sportType->name = '健身房';
        $sportTypeRoot->addChild($sportType);

        $sportType = new BSResourceGroup();
        $sportType->name = '游泳';
        $sportTypeRoot->addChild($sportType);

        $area = new BSResourceGroup();
        $area->name = '重庆';
        $areaRoot->addChild($area);
        
        $subArea = new BSResourceGroup();
        $subArea->name = '九龙坡区';
        $area->addChild($subArea);
        
        $subArea = new BSResourceGroup();
        $subArea->name = '渝中区';
        $area->addChild($subArea);
        
        $sportStadium = new BSResourceGroup();
        $sportStadium->name = '奥体体育公园运动中心';
        $sportStadium->picture = 's_1.jpg';
        $sportStadiumRoot->addChild($sportStadium);
        
        $sportStadium = new BSResourceGroup();
        $sportStadium->name = '重庆市体育馆';
        $sportStadium->picture = 's_2.jpg';
        $sportStadiumRoot->addChild($sportStadium);
    }
    
    function findByConstantId($cid) {
        switch ($cid) {
            case self::SPORT_TYPE:
                return BSResourceGroup::find('Sport Type');
            case self::AREA:
                return BSResourceGroup::find('Area');
            case self::STADIUM:
                return BSResourceGroup::find('Sport Stadium');

            default:
                break;
        }
        
        return null;
    }
}
